/*
 * TimeTaggerSCPI.cpp
 *
 *  Created on: 18.03.2013
 *      Author: mag
 */

#include "TimeTaggerSCPI.h"

TimeTaggerSCPI::TimeTaggerSCPI() {
}

TimeTaggerSCPI::~TimeTaggerSCPI() {
}

SCPIContext *TimeTaggerSCPI::new_context() {
	TimeTaggerSCPIContext *context=new TimeTaggerSCPIContext(this);
	return context;
}

TimeTaggerSCPIContext::TimeTaggerSCPIContext(SCPI *scpi)
: SCPIContext(scpi) {
	cmdlist=TimeTaggerSCPI::scpi_commands;
	current_slot=-1;
}

#define FORWARDER(name) \
	static scpi_result_t name(scpi_t * context) { \
	TimeTaggerSCPIContext *ctx= (TimeTaggerSCPIContext*) context; \
	TimeTaggerSCPI *scpi = (TimeTaggerSCPI *) ctx->scpi; \
	return scpi->name(ctx); \
	}


FORWARDER(IDN)
FORWARDER(SYST_VERS)

FORWARDER(CONF_USE)
FORWARDER(CONF_USE_Q)
FORWARDER(CONF_HELP)
FORWARDER(CONF_LIST)

FORWARDER(CONF_OVER)
FORWARDER(CONF_OVER_HELP)
FORWARDER(CONF_COUNT)
FORWARDER(CONF_COUNT_HELP)
FORWARDER(CONF_COUNTR)
FORWARDER(CONF_COUNTR_HELP)
FORWARDER(CONF_HISTO)
FORWARDER(CONF_HISTO_HELP)
FORWARDER(CONF_DIST)
FORWARDER(CONF_DIST_HELP)
FORWARDER(CONF_CHISTO)
FORWARDER(CONF_CHISTO_HELP)
FORWARDER(CONF_COUNTB)
FORWARDER(CONF_COUNTB_HELP)
FORWARDER(CONF_PULSED)
FORWARDER(CONF_PULSED_HELP)


typedef scpi_command_callback_t CMD;
static const scpi_command_t commands[] = {
	/* IEEE Mandated Commands (SCPI std V1999.0 4.1.1) */
	{ "*CLS", SCPI_CoreCls },
	{ "*ESE", SCPI_CoreEse },
	{ "*ESE?", SCPI_CoreEseQ },
	{ "*ESR?", SCPI_CoreEsrQ },
	{ "*IDN?", IDN },
	{ "*OPC", SCPI_CoreOpc },
	{ "*OPC?", SCPI_CoreOpcQ },
	{ "*RST", SCPI_CoreRst },
	{ "*SRE", SCPI_CoreSre },
	{ "*SRE?", SCPI_CoreSreQ },
	{ "*STB?", SCPI_CoreStbQ },
	{ "*TST?", SCPI_CoreTstQ },
	{ "*WAI", SCPI_CoreWai },

	/* Required SCPI commands (SCPI std V1999.0 4.2.1) */
	{"SYSTem:ERRor?", SCPI_SystemErrorNextQ },
	{"SYSTem:ERRor:NEXT?", SCPI_SystemErrorNextQ },
	{"SYSTem:ERRor:COUNt?", SCPI_SystemErrorCountQ },
	{"SYSTem:VERSion?", SYST_VERS },

	//{"STATus:OPERation?", scpi_stub_callback,},
	//{"STATus:OPERation:EVENt?", scpi_stub_callback,},
	//{"STATus:OPERation:CONDition?", scpi_stub_callback,},
	//{"STATus:OPERation:ENABle", scpi_stub_callback,},
	//{"STATus:OPERation:ENABle?", scpi_stub_callback,},

	{ "STATus:QUEStionable?", SCPI_StatusQuestionableEventQ  },
	{ "STATus:QUEStionable:EVENt?", SCPI_StatusQuestionableEventQ  },
	//{"STATus:QUEStionable:CONDition?", scpi_stub_callback },
	{ "STATus:QUEStionable:ENABle", SCPI_StatusQuestionableEnable  },
	{ "STATus:QUEStionable:ENABle?", SCPI_StatusQuestionableEnableQ },

	{ "STATus:PRESet", SCPI_StatusPreset },

	/* TitmTagger CONFigure subsystem */
	{ "CONFigure:USE", CONF_USE },
	{ "CONFigure:USE?", CONF_USE_Q },
	{ "CONFigure:HELP?", CONF_HELP },
	{ "CONFigure:LIST?", CONF_LIST },

	{ "CONFigure:OVERflow:HELP?", CONF_OVER_HELP },
	{ "CONFigure:OVERflow", CONF_OVER },
	{ "CONFigure:COUNTer:HELP?", CONF_COUNT_HELP },
	{ "CONFigure:COUNTer", CONF_COUNT },
	{ "CONFigure:COUNTRate:HELP?", CONF_COUNTR_HELP },
	{ "CONFigure:COUNTRate", CONF_COUNTR },
	{ "CONFigure:HISTOgram:HELP?", CONF_HISTO_HELP },
	{ "CONFigure:HISTOgram", CONF_HISTO },
	{ "CONFigure:DISTribution:HELP?", CONF_DIST_HELP },
	{ "CONFigure:DISTribution", CONF_DIST },
	{ "CONFigure:CHISTOgram:HELP?", CONF_CHISTO_HELP },
	{ "CONFigure:CHISTOgram", CONF_CHISTO },
	{ "CONFigure:COUNBetweenmarkers:HELP?", CONF_COUNTB_HELP },
	{ "CONFigure:COUNBetweenmarkers", CONF_COUNTB },
	{ "CONFigure:PULSED:HELP?", CONF_PULSED_HELP },
	{ "CONFigure:PULSED", CONF_PULSED },


	{ 0, 0 }
};

const scpi_command_t *TimeTaggerSCPI::scpi_commands=commands;
